package com.song.controller.admin;


import com.song.entity.BorrowInfo;
import com.song.entity.vo.BorrowInfoApprovalVO;
import com.song.result.Result;
import com.song.service.BorrowInfoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Song
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/admin/core/borrowInfo")
public class AdminBorrowInfoController {

    @Autowired
    private BorrowInfoService borrowInfoService;


    @ApiOperation("显示借款列表")
    @GetMapping("/list")
    public Result list(){
        List<BorrowInfo> borrowInfoList = borrowInfoService.selectList();
        return Result.ok().data("list",borrowInfoList);

    }


    //http://localhost/admin/core/borrowInfo/show/1
    @ApiOperation("显示借款详情,即借款信息和借款人信息")
    @GetMapping("/show/{id}")
    public Result show(@ApiParam(value = "借款id",required = true) @PathVariable Long id){

        //根据借款信息id查询借款信息,向前端返回map类型
        Map<String,Object> param = borrowInfoService.getBorrowInfoAndBorrowById(id);

        return Result.ok().data("borrowInfoDetail",param);

    }


    //http://localhost/admin/core/borrowInfo/approval
    @ApiOperation("生成标的信息")
    @PostMapping("/approval")
    public Result approval(@RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO){
        //判断条件
        if (borrowInfoApprovalVO == null){
            //前端没有写表单
            return Result.error().message("请先填写数据！");
        }
        //不为空
        borrowInfoService.approval(borrowInfoApprovalVO);

        return Result.ok().message("审批成功");

    }

}

